package com.riatimes.mvc.view 
{
	import flash.display.Sprite;
	import flash.events.Event;
	/**
	 * 基础组件
	 * @author Nick Wong
	 */
	public class BaseComponent extends Sprite
	{
		public var scaleFromStage:Number = 0.8;
		/**
		 * 构造函数
		 */
		public function BaseComponent() 
		{
			this.addEventListener(Event.ADDED_TO_STAGE, __addToStageHandle, false, 0, true);
		}
		
		private function __addToStageHandle(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, __addToStageHandle);
			this.addEventListener(Event.REMOVED_FROM_STAGE, __removeFromStageHandle, false, 0, true);
			stage.addEventListener(Event.RESIZE, __resizeHandle, false, 0, true);
			/*this.alpha = 0;
			TweenMax.to(this,1,{alpha:1,ease:Strong.easeOut});*/
			initUI();
			initLocation();
			initEvent();
			start();
		}
		
		public function start():void
		{
			
		}
		
		private function __resizeHandle(e:Event):void 
		{
			initLocation();
		}
		
		protected function __removeFromStageHandle(e:Event):void 
		{
			stage.removeEventListener(Event.RESIZE, __resizeHandle);
			removeEventListener(Event.REMOVED_FROM_STAGE, __removeFromStageHandle);
			dispose();
		}
		
		/**
		 * 初始化UI
		 */
		public function initUI():void {
			
		}
		/**
		 * 初始化位置
		 */
		public function initLocation():void {
			/*this.x = (stage.stageWidth - this.width) / 2;
			this.y = (stage.stageHeight - this.height) / 2;*/
		}
		/**
		 * 初始化事件
		 */
		public function initEvent(b:Boolean=true):void {
			
		}
		/**
		 * 注销
		 */
		public function dispose():void
		{	
			while (this.numChildren) this.removeChildAt(0);
			initEvent(false);
			
		}
		
	}
	
}